

def get_breadcrumb(category):
    """
      获取面包屑导航
      category: 商品类别
      return: 面包屑导航字典
      """
    breadcrumb = dict(
        cat1 = '',
        cat2 = '',
        cat3 = ''
    )
    # 当前分类没有parent就是顶级, 一级分类
    if category.parent is None:
        breadcrumb['cat1'] = category
    elif category.subs.count() == 0:
        # 当前分类没有子类subs就是最底级, 二级分类
        breadcrumb['cat3'] = category
        breadcrumb['cat2'] = category.parent
        breadcrumb['cat1'] = category.parent.parent
    else:
        # 有父类有子类就是二级分类
        breadcrumb['cat2'] = category
        breadcrumb['cat1'] = category.parent

    return breadcrumb

